import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'

let _this = null;
let styleType = [
  '单行平铺',
  '多行平铺',
  '平铺多级联动',
  '弹框列表',
  '弹框多级联动',
]
let messageSort = [
  { name: '基本信息', value: '1' },
  { name: '服务信息', value: '2' },
  { name: '置业需求', value: '3' },
  { name: '客户画像', value: '4' },
]
class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [{
      title: '字段名称',
      field: 'fieldValue',
      width: 180,
      align: 'center',
      slots: {
        default: (params, h) => {
          return [h('div', [
            params.row.fieldDescription ?
            h(
              'Tooltip', {
                props: {
                  placement: 'right',
                  transfer: true
                },
                // style: {
                //   display: 'flex'
                // },
              },
              [
                h('span', params.row.fieldValue),
                h('Icon', {
                  props: {
                    type: 'ios-help',
                  },
                  style: {
                    fontWeight: '700',
                    fontSize: '14px',
                    color: 'red',
                    border: '1px solid red',
                    borderRadius: '50%',
                    marginLeft: '5px',
                    width: '18px',
                    height: '18px',
                    verticalAlign: 'textTop',
                  },
                }),
                h(
                  'div', {
                    slot: 'content',
                  },
                  params.row.fieldDescription
                ),
              ]
            ) :
            h('span', params.row.fieldValue),
          ])]
        }
      },
    }, {
      title: '是否必填',
      field: 'ifRequired',
      minWidth: 100,
      align: 'center',
      slots: {
        default: (params, h) => {
          return params.row.ifRequired == 1 ? '是' : '否'
        },
      }
    }, {
      title: '字段属性',
      field: 'fieldType',
      width: 120,
      align: 'center',
      slots: {
        default: (params, h) => {
          return params.row.fieldType == 1 ?
            '系统字段' :
            params.row.fieldType == 2 ?
            '默认字段' :
            params.row.fieldType == 3 ?
            '扩展字段' :
            '-'
        },
      }
    }, {
      title: '类型',
      field: 'inputType',
      minWidth: 120,
      align: 'center',
      slots: {
        default: (params, h) => {
          let inputType = params.row.inputType
          return inputType == 1 ? '填空' : inputType == 2 ? '单选' : '多选'
        },
      }
    }, {
      title: '状态',
      field: 'validate',
      minWidth: 120,
      align: 'center',
      slots: {
        default: (params, h) => {
          return params.row.validate == 1 ? '启用' : '禁用'
        },
      }
    }, {
      title: '样式',
      field: 'styleType',
      minWidth: 120,
      align: 'center',
      slots: {
        default: (params, h) => {
          return styleType[params.row.styleType - 1]
        },
      }
    }, {
      title: '内容',
      field: 'content',
      minWidth: 120,
      align: 'center',
      slots: {
        default: (params, h) => {
          let { content, fieldUnit } = params.row
          return !!content && !!fieldUnit ? `${content}, 单位为${fieldUnit}` :
            !!content ? content : !!fieldUnit ? `单位为${fieldUnit}` : '-'
        },
      }
    }, {
      title: '信息分类',
      field: 'infoType',
      minWidth: 120,
      align: 'center',
      slots: {
        default: (params, h) => {
          return messageSort[params.row.infoType - 1] ?
            messageSort[params.row.infoType - 1].name : '-'
        },
      }
    }, ]
  }
}


export default Column